﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Classified.Data;
using Classified.Data.Repositories;
using Classified.Domain.Entities;



namespace Classified.Service
{
    public static class CategoryExtensions
    {
        //public static string GetCategoryBreadCrumb(this ServiceDirectory category, IDirectoryServiceService categoryService)
        //{
        //    string result = string.Empty;

        //    while (category != null && !category.Deleted)
        //    {
        //        if (String.IsNullOrEmpty(result))
        //            result = category.Name;
        //        else
        //           // result = category.Name + ">" + result;
        //            result = HttpUtility.HtmlDecode("&nbsp;") + ">" + result;

        //        category = categoryService.Find(category.ParentCategoryId);

        //    }
        //    return result;
        //}  
        //public static string GetCategoryBreadCrumbMore(this ServiceDirectory category, IDirectoryServiceService categoryService)
        //{
        //    string result = string.Empty;

        //    while (category != null && !category.Deleted)
        //    {
        //        if (String.IsNullOrEmpty(result))
        //            result = category.Name;
        //        else
        //            result = category.Name + " >> " + result;

        //        category = categoryService.Find(category.ParentCategoryId);

        //    }
        //    return result;
        //}
        public static string GetClassifiedCategoryBreadCrumb(this ClassifiedCategory category, IClassifiedAdCategoryRepository categoryService)
        {
            string result = string.Empty;

            while (category != null && !category.Deleted)
            {
                if (String.IsNullOrEmpty(result))
                    result = category.Name;
                else
                    // result = category.Name + ">" + result;
                    result = HttpUtility.HtmlDecode("&nbsp;") + ">" + result;

                category = categoryService.GetById(category.ParentCategoryId);

            }
            return result;
        }
        public static string GetClassifiedCategoryBreadCrumbMore(this ClassifiedCategory category, IClassifiedAdCategoryRepository categoryService)
        {
            string result = string.Empty;

            while (category != null && !category.Deleted)
            {
                if (String.IsNullOrEmpty(result))
                    result = category.Name;
                else
                    result = category.Name + " >> " + result;

                    category = categoryService.GetById(category.ParentCategoryId);

            }
            return result;
        }
        public static string GetLocationBreadCrumbMore(this Location location, ILocationRepository locationRepository)
        {
            string result = string.Empty;

            while (location != null)
            {
                if (String.IsNullOrEmpty(result))
                    result = location.Name;
                else
                    result = location.Name + " >> " + result;

                location = locationRepository.GetById(location.ParentId);

            }
            return result;
        }
        public static string BuildCategory(this ClassifiedCategory category, IClassifiedAdCategoryRepository categoryRepository)
        {
            string result = string.Empty;

            while (category != null)
            {
                if (String.IsNullOrEmpty(result))
                    result = category.Name;
                else
                    result += ","+ category.Name + "," + result;

                category = categoryRepository.GetById(category.ParentCategoryId);

            }
            return result;
        }
    }
}